package com.ruoyi.project.sms.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.db.sms.domain.SmsCoupon;
import com.ruoyi.db.sms.domain.query.SmsCouponQueryVo;
import com.ruoyi.project.sms.service.SmsCouponService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 优惠券Controller
 *
 * @author yfy
 * @date 2020-04-24
 */
@Api(tags="sms管理：优惠券管理")
@RestController
@RequestMapping("/sms/coupon")
public class SmsCouponController extends BaseController
{
    @Autowired
    private SmsCouponService smsCouponService;

    @ApiOperation("查询优惠券列表")
    @PreAuthorize("@ss.hasPermi('sms:coupon:list')")
    @GetMapping("/list")
    public TableDataInfo list(SmsCouponQueryVo smsCouponQueryVo)
    {
        startPage();
        List<SmsCoupon> list = smsCouponService.selectSmsCouponList(smsCouponQueryVo);
        return getDataTable(list);
    }

    @ApiOperation("导出优惠券列表")
    @Log(title = "优惠券", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('sms:coupon:export')")
    @GetMapping("/export")
    public AjaxResult export(SmsCouponQueryVo smsCouponQueryVo)
    {
        List<SmsCoupon> list = smsCouponService.selectSmsCouponList(smsCouponQueryVo);
        ExcelUtil<SmsCoupon> util = new ExcelUtil<SmsCoupon>(SmsCoupon.class);
        return util.exportExcel(list, "coupon");
    }

    @ApiOperation("获取优惠券详细信息")
    @Log(title = "优惠券", businessType = BusinessType.OTHER)
    @PreAuthorize("@ss.hasPermi('sms:coupon:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(smsCouponService.selectSmsCouponById(id));
    }

    @ApiOperation("新增优惠券")
    @Log(title = "优惠券", businessType = BusinessType.INSERT)
    @PreAuthorize("@ss.hasPermi('sms:coupon:add')")
    @PostMapping
    public AjaxResult add(@RequestBody SmsCoupon smsCoupon)
    {
        return toAjax(smsCouponService.insertSmsCoupon(smsCoupon));
    }

    @ApiOperation("修改优惠券")
    @Log(title = "优惠券", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('sms:coupon:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody SmsCoupon smsCoupon)
    {
        return toAjax(smsCouponService.updateSmsCoupon(smsCoupon));
    }

    @ApiOperation("删除优惠券")
    @Log(title = "优惠券", businessType = BusinessType.DELETE)
    @PreAuthorize("@ss.hasPermi('sms:coupon:remove')")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(smsCouponService.deleteSmsCouponByIds(ids));
    }
}
